package com.smartian.scan.filesearch;

import android.content.Context;

import com.smartian.scan.filesearch.bean.TreeNodeFile;
import com.smartian.scan.filesearch.impl.callbacks.LogOpCallback;
import com.smartian.scan.filesearch.interfaces.IDispatcher;
import com.smartian.scan.filesearch.interfaces.IFilter;
import com.smartian.scan.filesearch.interfaces.ISearchCallback;

import java.util.Arrays;
import java.util.List;

public class SearchTaskManager {

    private volatile static SearchTaskManager instance = null;
    private static Context mContext = null;


    public static SearchTaskManager shareInstance() {
        if (instance == null) {
            synchronized (SearchTaskManager.class) {
                if (instance == null) {
                    instance = new SearchTaskManager();
                }
            }
        }
        return instance;
    }

    public static Context getContext() {
        return mContext;
    }

    public static void setContext(Context context) {
        SearchTaskManager.mContext = context;
    }

    public void startSearch(Context context, List<String> dirs, long timeout, List<IFilter> filters, int engineType, ISearchCallback callback ) {

        DispatcherManager.TaskBuilder taskBuilder = new DispatcherManager.TaskBuilder();
        taskBuilder.timeout(timeout);
        taskBuilder.dirPaths(dirs);
        taskBuilder.addFilters(filters);
        taskBuilder.context(context);
        taskBuilder.engineType(engineType);
        IDispatcher dispatcher =  taskBuilder.build();
        dispatcher.start();


    }

    public void startSearch(Context context,List<String> dirs, ISearchCallback callback ) {
        startSearch(context,dirs,0l,null, DispatcherManager.SEARCH_DISPATCHER_TREE_TASK,callback);
    }



}
